Accept -j as a command-line parameter
authorAlex Crichton <alex@alexcrichton.com>
Sat, 28 Jun 2014 23:54:16 +0000 (16:54 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Mon, 30 Jun 2014 23:00:33 +0000 (16:00 -0700)
This parameter will be used to control the number of concurrent builds that
cargo has executing.

src/bin/cargo-build.rs
src/bin/cargo-git-checkout.rs
src/bin/cargo-test.rs
src/cargo/ops/cargo_compile.rs
src/cargo/util/config.rs

index f88cf5405ff1710a8d339f295b5346c51ec74ed6..5a475ef138be8fe15c1619d32eb4663285511cd3 100755 (executable)
@@ -21,11 +21,13 @@ use cargo::util::important_paths::find_project_manifest;
 #[deriving(PartialEq,Clone,Decodable,Encodable)]
 pub struct Options {
     manifest_path: Option<String>,
-    update_remotes: bool
+    update_remotes: bool,
+    jobs: Option<uint>,
 }
 
 hammer_config!(Options "Build the current project", |c| {
     c.short("update_remotes", 'u')
+     .short("jobs", 'j')
 })
 
 fn main() {
@@ -46,8 +48,9 @@ fn execute(options: Options, shell: &mut MultiShell) -> CliResult<Option<()>> {
     };
 
     let update = options.update_remotes;
+    let jobs = options.jobs;
 
-    ops::compile(&root, update, "compile", shell).map(|_| None).map_err(|err| {
+    ops::compile(&root, update, "compile", shell, jobs).map(|_| None).map_err(|err| {
         CliError::from_boxed(err, 101)
     })
 }
index a7c1901032486a6143e5b5ba4a3e41ffc9b3f303..8ce3bee7aae422416b63914948417bff21fea5b8 100644 (file)
@@ -37,7 +37,9 @@ fn execute(options: Options, shell: &mut MultiShell) -> CliResult<Option<()>> {
 
     let source_id = SourceId::for_git(&url, reference.as_slice());
 
-    let mut config = try!(Config::new(shell, true).map_err(|e| CliError::from_boxed(e, 1)));
+    let mut config = try!(Config::new(shell, true, None).map_err(|e| {
+        CliError::from_boxed(e, 1)
+    }));
     let mut source = GitSource::new(&source_id, &mut config);
 
     try!(source.update().map_err(|e| {
index 5adb71120458ff122895686f9826193eb6fe35c9..4becf95a6a37303dfce2ce5bd2e409a91376dcd3 100755 (executable)
@@ -21,10 +21,13 @@ use cargo::util::important_paths::find_project_manifest;
 #[deriving(PartialEq,Clone,Decodable)]
 struct Options {
     manifest_path: Option<String>,
-    rest: Vec<String>
+    jobs: Option<uint>,
+    rest: Vec<String>,
 }
 
-hammer_config!(Options "Run the package's test suite")
+hammer_config!(Options "Run the package's test suite", |c| {
+    c.short("jobs", 'j')
+})
 
 fn main() {
     execute_main_without_stdin(execute);
@@ -41,7 +44,8 @@ fn execute(options: Options, shell: &mut MultiShell) -> CliResult<Option<()>> {
                     }))
     };
 
-    try!(ops::compile(&root, false, "test", shell).map(|_| None::<()>).map_err(|err| {
+    try!(ops::compile(&root, false, "test", shell, options.jobs)
+             .map(|_| None::<()>).map_err(|err| {
         CliError::from_boxed(err, 101)
     }));
 
index f8a1b9e231b613b31a3f9b87e7dc75b5401060aa..789f65e3e26855eeec66318adbbc8e4b9ca75a7c 100644 (file)
@@ -31,7 +31,8 @@ use sources::{PathSource};
 use util::{CargoResult, Wrap, config, internal, human};
 
 pub fn compile(manifest_path: &Path, update: bool,
-               env: &str, shell: &mut MultiShell) -> CargoResult<()>
+               env: &str, shell: &mut MultiShell,
+               jobs: Option<uint>) -> CargoResult<()>
 {
     log!(4, "compile; manifest-path={}", manifest_path.display());
 
@@ -51,7 +52,7 @@ pub fn compile(manifest_path: &Path, update: bool,
     let source_ids = package.get_source_ids();
 
     let packages = {
-        let mut config = try!(Config::new(shell, update));
+        let mut config = try!(Config::new(shell, update, jobs));
 
         let mut registry =
             try!(PackageRegistry::new(source_ids, override_ids, &mut config));
@@ -70,7 +71,7 @@ pub fn compile(manifest_path: &Path, update: bool,
         target.get_profile().get_env() == env
     }).collect::<Vec<&Target>>();
 
-    let mut config = try!(Config::new(shell, update));
+    let mut config = try!(Config::new(shell, update, jobs));
     try!(ops::compile_targets(targets.as_slice(), &package,
          &PackageSet::new(packages.as_slice()), &mut config));
 
index 898d025b5414ec053a51ad57b1b4012ebf5cc47f..34e7ec5a6b836e59eacd8df74c5fe7c9f196c833 100644 (file)
@@ -10,18 +10,25 @@ use cargo_toml = util::toml;
 pub struct Config<'a> {
     home_path: Path,
     update_remotes: bool,
-    shell: &'a mut MultiShell
+    shell: &'a mut MultiShell,
+    jobs: uint,
 }
 
 impl<'a> Config<'a> {
-    pub fn new<'a>(shell: &'a mut MultiShell, update_remotes: bool) -> CargoResult<Config<'a>> {
+    pub fn new<'a>(shell: &'a mut MultiShell,
+                   update_remotes: bool,
+                   jobs: Option<uint>) -> CargoResult<Config<'a>> {
+        if jobs == Some(0) {
+            return Err(human("jobs must be at least 1"))
+        }
         Ok(Config {
             home_path: try!(os::homedir().require(|| {
                 human("Cargo couldn't find your home directory. \
                       This probably means that $HOME was not set.")
             })),
             update_remotes: update_remotes,
-            shell: shell
+            shell: shell,
+            jobs: jobs.unwrap_or(os::num_cpus()),
         })
     }
 
@@ -40,6 +47,10 @@ impl<'a> Config<'a> {
     pub fn update_remotes(&mut self) -> bool {
         self.update_remotes
     }
+
+    pub fn jobs(&mut self) -> uint {
+        self.jobs
+    }
 }
 
 #[deriving(Eq,PartialEq,Clone,Encodable,Decodable)]